package com.sgb.kjwl.view.widget.lease;

import android.content.Context;
import android.util.SparseBooleanArray;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.lease.DictEntity4;
import com.sgb.kjwl.model.entity.request.HouseFilterJson;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.view.ui.adapter.material.MaterialFilterAdapter3;
import com.swgk.core.customview.MaxRecyclerView;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.ArrayList;
import java.util.List;

/**
 * 租赁-成员公司筛选界面
 */
public class LeaseCompanyFliterPopWindow extends BasePopWindow {
    private TextView typeView;
    private MaxRecyclerView typeRecyclerView;
    private MaterialFilterAdapter3 typeAdapter;
    private FilterResultClick filterResultClick;
    private boolean isFir = true;

    public interface FilterResultClick {
        void result(String no);
    }

    public void setFilterResultClick(FilterResultClick filterResultClick) {
        this.filterResultClick = filterResultClick;
    }

    public LeaseCompanyFliterPopWindow(Context context) {
        super(context, DIR_RIGHT);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwin_lease_company_fliter;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        typeView = holder.getPop().findViewById(R.id.type_view);
        typeRecyclerView = holder.getPop().findViewById(R.id.type_list);
        typeRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));
        typeAdapter = new MaterialFilterAdapter3(mContext, null);
        typeAdapter.setItemSelect(true);
        typeAdapter.setDefItem(-1);
        typeAdapter.setOnItemClick(new AdapterOnItemClick<DictEntity3>() {
            @Override
            public void onItemClick(DictEntity3 materialFilterEntity, int position) {
                if (filterResultClick != null) {
                    filterResultClick.result(materialFilterEntity.getId());
                    dismiss();
                }
            }
        });
        typeRecyclerView.setAdapter(typeAdapter);
    }

    public void setTypeData(List<DictEntity3> data) {
        if (isFir) {
            typeAdapter.setDefItem(0);
            isFir = false;
        }
        typeAdapter.setDatas(data);
    }

    public void setTypeDefault(int position, String name) {
        this.typeView.setText(name);
        this.typeAdapter.setDefItem(position);
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }
}
